﻿namespace NMortgage.UI.Tests.Model
{
    using System;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using NMortgage.UI.Model;

    [TestClass]
    public class BetaDistributionTest
    {
        #region Properties

        private BetaDistribution Subject
        {
            get;
            set;
        }

        #endregion Properties

        #region Methods

        [TestMethod]
        public void AlphaTest()
        {
            double expected = 1d;
            double actual;
            Subject.Alpha = expected;
            actual = Subject.Alpha;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void BetaTest()
        {
            double expected = 1d;
            double actual;
            Subject.Beta = expected;
            actual = Subject.Beta;
            Assert.AreEqual(expected, actual);
        }

        //[TestMethod]
        //public void GenerateDataFileTest()
        //{
        //    Subject.Minimum = 3;
        //    Subject.Maximum = 5;
        //    double actual;
        //    using (System.IO.StreamWriter sw = System.IO.File.AppendText(@"C:\temp\beta100000.txt"))
        //    {
        //        for (int i = 0; i < 100000; i++)
        //        {
        //            actual = Subject.GetRate();
        //            sw.WriteLine(actual);
        //        }
        //    }
        //    Assert.IsTrue(true);
        //}
        [TestMethod]
        public void GetRateTest()
        {
            Subject.Minimum = 3;
            Subject.Maximum = 5;
            double actual;
            bool result;

            for (int i = 0; i < 1000000; i++)
            {
                actual = Subject.GetRate();
                result = IsBetween(actual, Subject.Minimum, Subject.Maximum);
                Assert.IsTrue(result);
            }
        }

        [TestInitialize]
        public void InitializeTest()
        {
            Subject = new BetaDistribution();
        }

        [TestMethod]
        public void MaximumTest()
        {
            double expected = 1d;
            double actual;
            Subject.Maximum = expected;
            actual = Subject.Maximum;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void MinimumTest()
        {
            double expected = 1d;
            double actual;
            Subject.Minimum = expected;
            actual = Subject.Minimum;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void RateDescriptionTest()
        {
            string actual;
            actual = Subject.Description;
            Assert.IsNotNull(actual);
        }

        private bool IsBetween(double target, double min, double max)
        {
            return (target >= (min / 100d) && target <= (max / 100d));
        }

        #endregion Methods
    }
}